#include "heroplane.h"

HeroPlane::HeroPlane()
{
    //加载飞机图片
    m_Plane.load(HERO_PATH1);
    //初始化飞机坐标
    m_x=(GAME_WIDTH-m_Plane.width())*0.5;
    m_y=(GAME_HEIGHT-m_Plane.height());
    //初始化边框
    m_Rect.setWidth(m_Plane.width()-100);
    m_Rect.setHeight(m_Plane.height()-10);
    m_Rect.moveTo(m_x+50,m_y+5);
    //初始化伤害
    m_Hurt=BULLET1_HURT;

    //初始化血量
    m_Hero_Blood=HERO1_BLOOD;
    //初始化蓝
    m_HERO_Blue=HERO1_BLUE;
    //初始化护盾
    m_Shield_x=-100;
    m_Shield_y=-100;
    m_shield_free=1;
    m_Shield.load(":/rec.image/Defend_imag.png");
    m_Shield_rect.moveTo(m_Shield_x,m_Shield_y);

    //特殊子弹
    for(int i=0;i<BULL_NUM2;i++)
    {
        m_special_bullets[i].m_Bullet.load(":/rec.image/Bullet05.png");
    }
    //特殊子弹
    for(int i=0;i<BULL_NUM3;i++)
    {
        m_special_bullets2[i].m_Bullet.load(":/rec.image/Bullet09.png");
    }
    //特殊子弹
    for(int i=0;i<BULL_NUM3;i++)
    {
        m_special_bullets3[i].m_Bullet.load(":/rec.image/Bullet09.png");
    }



}
//发射子弹
void HeroPlane::shoot()
{
    //累加时间间隔
     m_Recorder++;
     //如果记录的数字未达到发射子弹的时间间隔，不发射子弹
     if(m_Recorder<BULL_INTERVAL-time)
     {
         return;
     }
     //达到发射时间
     m_Recorder=0;
     //shoot_music->play();

     //发射一行子弹

     for(int i=0;i<BULL_NUM;i++)
     {

         //如果是空闲子弹 进行发射
         if(m_bullets1[i].m_Free)
         {
             if(AddNum==1)
             {
                 //如果AddNum==1，发射一行子弹
                 //发射
                 m_bullets1[i].m_Free=0;
                 //设置子弹坐标
                 m_bullets1[i].m_x=m_x-3;
                 m_bullets1[i].m_y=m_y-40;
                 break;
             }
             //发射两行子弹
             else if(AddNum==2)
             {
                 m_bullets1[i].m_Free=0;
                 m_bullets1[i].m_x=m_x-33;
                 m_bullets1[i].m_y=m_y-40;

                 m_bullets3[i].m_Free=0;
                 m_bullets3[i].m_x=m_x+27;
                 m_bullets3[i].m_y=m_y-40;
                 break;
             }
             //三行
             else if(AddNum==3)
             {
                 m_bullets1[i].m_Free=0;
                 m_bullets1[i].m_x=m_x-3;
                 m_bullets1[i].m_y=m_y-40;

                 m_bullets2[i].m_Free=0;
                 m_bullets2[i].m_x=m_x-33;
                 m_bullets2[i].m_y=m_y-40;

                 m_bullets3[i].m_Free=0;
                 m_bullets3[i].m_x=m_x+27;
                 m_bullets3[i].m_y=m_y-40;
                break;
             }
         }

     }

}

void HeroPlane::shoot2()
{

    //累加时间间隔
     m_Recorder2++;
     //如果记录的数字未达到发射子弹的时间间隔，不发射子弹
     if(m_Recorder2<BULL_SPECIAL_INTERVAL)
     {
         return;
     }
     //达到发射时间
     m_Recorder2=0;
     //发射一行子弹

     for(int i=0;i<BULL_NUM2;i++)
     {
         if(m_special_bullets[i].m_Free)
         {
             m_special_bullets[i].m_Free=0;
             m_special_bullets[i].m_x=m_x+35;
             m_special_bullets[i].m_y=m_y-60;
             break;

         }

     }
}

void HeroPlane::shoot3()
{
    //累加时间间隔
     m_Recorder3++;
     //如果记录的数字未达到发射子弹的时间间隔，不发射子弹
     if(m_Recorder3<BULL_SPECIAL_INTERVAL2)
     {
         return;
     }
     //达到发射时间
     m_Recorder3=0;
     //发射一行子弹

     for(int i=0;i<BULL_NUM2;i++)
     {
         if(m_special_bullets2[i].m_Free)
         {
             m_special_bullets2[i].m_Free=0;
             m_special_bullets2[i].m_x=m_x+90;
             m_special_bullets2[i].m_y=m_y-60;
             break;

         }

     }
}

void HeroPlane::shoot4()
{
    //累加时间间隔
     m_Recorder4++;
     //如果记录的数字未达到发射子弹的时间间隔，不发射子弹
     if(m_Recorder4<BULL_SPECIAL_INTERVAL2)
     {
         return;
     }
     //达到发射时间
     m_Recorder4=0;
     //发射一行子弹

     for(int i=0;i<BULL_NUM2;i++)
     {
         if(m_special_bullets3[i].m_Free)
         {
             m_special_bullets3[i].m_Free=0;
             m_special_bullets3[i].m_x=m_x-15;
             m_special_bullets3[i].m_y=m_y-60;
             break;

         }

     }
}

//设置战机位置
void HeroPlane::setPOsition(int x, int y)
{
    m_x=x;
    m_y=y;
    m_Rect.moveTo(m_x+50,m_y+5);
}
//护盾出现
void HeroPlane::Shield()
{
    if(m_shield_free==0)
    {
        m_Shield_x=m_x;
        m_Shield_y=m_y;
        m_Shield_rect.moveTo(m_Shield_x,m_Shield_y);
    }
}
